import datetime
import json
import random

import pymysql
import requests
from snowflake import client

connect = pymysql.connect(host='127.0.0.1', user='root', password='1905120210', port=3306, database='video-recommendation-system')
cursor = connect.cursor()

# 查询comment表，随机生成收藏信息
cursor.execute('select uid,vid from comment limit 0,50')
fetchall = cursor.fetchall()
for f in fetchall:
    uid = f[0]
    vid = f[1]
    create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    deleted = 0
    deleted_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    try:
        cursor.execute('insert into collect(uid,vid,create_time,deleted,deleted_time) values (%s,%s,%s,%s,%s) ',(uid,vid,create_time,deleted,deleted_time))
        connect.commit()
    except Exception as e:
        print('collect插入出现问题：%s' % (e))
        connect.rollback()